package com.biz.controller.jobManage;

/*************************************************************************
 * 文件名称 ：JobManageController                        
 * 描述说明 ：作业管理器
 * 
 * 创建信息 : create by xy on 2014-5-10
 * 修订信息 : modify by (person) on (date) for (reason)
 * 
 * 版权信息 : Copyright (c) 2014 扬州北斗科技有限公司 
 **************************************************************************/
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.biz.controller.Jobs.TestController;
import com.biz.model.Pmodel.job.MgroupQuartzManage;
import com.biz.model.Pmodel.sys.Puser;
import com.biz.model.common.Pager;
import com.biz.service.HService.jobManage.JobManageServiceI;
import com.biz.utils.PagerPropertyUtils;
import com.biz.utils.StringUtil;
import com.framework.controller.BaseController;
import com.jd.open.api.sdk.domain.jzt_zw.DspAdMediaService.ArrayList;

@Controller
@RequestMapping("/jobManage")
public class JobManageController extends BaseController {
	private static final Logger LOGGER = LoggerFactory.getLogger(JobManageController.class);
	
	@Resource(name="jobManageService")
	private JobManageServiceI jobManageService;
	
	@RequestMapping("/showJobManageGrid")
	public void showJobManageGrid(HttpServletResponse response,String dtGridPager) throws Exception{
		Pager pager = PagerPropertyUtils.copy(JSONObject.fromObject(dtGridPager));
		Map<String,Object> map = new HashMap<String,Object>();
		map=pager.getParameters();
		try {
			map.put("job_name", pager.getParameters().get("job_name").toString().trim());	
		} catch (Exception e) {}
		try {
			map.put("job_group", pager.getParameters().get("job_group").toString().trim());	
		} catch (Exception e) {}
		try {
			map.put("status", pager.getParameters().get("status").toString().trim());	
		} catch (Exception e) {}
		pager.setParameters(map);
		Pager<MgroupQuartzManage> list=null;
		try {
			list = jobManageService.findMgroupQuartz(pager);
		} catch (Exception e) {
			e.printStackTrace();
		}
		writeJson(list, response);
	}
	
	/**
	 * 获取所有任务组名
	 * @return
	 */
	@RequestMapping("/getAllJobGroup")
	public @ResponseBody List<String> getAllJobGroup(){
		List<String> list = null;
		try {
			list = jobManageService.getAllJobGroup();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	/**
	 * 改变调度器状态
	 */
	@RequestMapping("/changeStatus")
	public @ResponseBody boolean changeStatus(@RequestParam int status,String id){
		try {
			Map<String,Object> param = new HashMap<String,Object>();
			param.put("status",status);
			param.put("id",id);
			boolean f =jobManageService.updateMGroupQuartzStatuById(param);
			return f;
		} catch (Exception e) {
			LOGGER.error(e.getMessage());
			return false;
		}
	}
	
	/**
	 * 删除任务定时器
	 * @param id
	 * @return
	 */
	@RequestMapping("/delQuartzSchedule")
	public @ResponseBody boolean delQuartzSchedule(@RequestParam String id){
		try {
			Map<String,Object> param = new HashMap<String,Object>();
			param.put("status",MgroupQuartzManage.STATUS_TO_DELETE);
			param.put("id",id);
			boolean f =jobManageService.delMGroupQuartzStatuById(param);
			return f;
		} catch (Exception e) {
			LOGGER.error(e.getMessage());
			return false;
		}
	}
	
	/**
	 * 跳转至编辑
	 * @param id
	 */
	@RequestMapping("/toEdit")
	public void toEdit(String id,HttpServletResponse response){
		MgroupQuartzManage mgq = null;
		try {
			mgq = jobManageService.getMGroupQuartzById(id);
		} catch (Exception e) {
			LOGGER.error(e.getMessage());
		}
		writeJson(mgq,response);
	}
	

}